﻿using AutoMapper;
using MediatR;
using Traceability.APP.Application.Command.Pictures;
using Traceability.Damoin;
using Traceability.ErrorCode;
using Traceability.Infaseture;

namespace Traceability.APP.Application.CommandHadnLer.Prices
{
    public class UpdatepictureCommandHandLer : IRequestHandler<UpdatepictureCommand, APIResult<int>>
    {

        private readonly IBaseRepostiy<Picture> _picture;
        private readonly IMapper mapper;

        public UpdatepictureCommandHandLer(IBaseRepostiy<Picture> picture, IMapper mapper)
        {
            _picture = picture;
            this.mapper = mapper;
        }
        public async Task<APIResult<int>> Handle(UpdatepictureCommand request, CancellationToken cancellationToken)
        {
            APIResult<int> result = new APIResult<int>();
            var list = mapper.Map<Picture>(request);
            list.TraceType= list.TraceType;
            list.ImgType = list.ImgType;
            list.Imagepath = list.Imagepath;
            await _picture.Update(list);
            result.Code = ResultCode.Ok;
            result.Message = "批次修改成功";
            return await Task.FromResult(result);
        }
    }
}
